主题
创建数据库 - CreateDatabase
函数简介
创建数据库,返回一个数据库对象指针。若文件已存在则返回失败。
接口名称
CreateDatabaseDLL调用
c
long CreateDatabase(long ola, string dbName, string password);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| dbName | 字符串 | 数据库文件路径。 |
| password | 字符串 | 数据库密码。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long db = ola.CreateDatabase("data/app.db", "");
if (db != 0) {
int ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
ola.CloseDatabase(db);
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
long db = ola.CreateDatabase("data/app.db", "");
if (db != 0)
{
int ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
ola.CloseDatabase(db);
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
db = ola.CreateDatabase("data/app.db", "")
if db != 0:
ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)")
ola.CloseDatabase(db)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long db = ola.CreateDatabase("data/app.db", "");
if (db != 0) {
ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
ola.CloseDatabase(db);
}cpp
var ola = com("OlaPlug.OlaSoft")
var db = ola.CreateDatabase("data/app.db", "")
if(db) {
ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
ola.CloseDatabase(db)
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
db = ola.CreateDatabase("data/app.db", "")
If db <> 0 Then
ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
ola.CloseDatabase(db)
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
db = ola.CreateDatabase (“data/app.db“, ““)
.如果真 (db ≠ 0)
ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
ola.CloseDatabase (db)
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var db = ola.CreateDatabase("data/app.db", "");
if(db){
ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
ola.CloseDatabase(db);
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 db = ola.CreateDatabase("data/app.db", "")
如果真 (db ≠ 0)
{
ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
ola.CloseDatabase(db)
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long db = ola.CreateDatabase("data/app.db", "");
if (db != 0) {
ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
ola.CloseDatabase(db);
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long db = CreateDatabase(instance, "data/app.db", "");
if (db != 0) {
int ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
CloseDatabase(instance, db);
}csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
long instance = CreateCOLAPlugInterFace();
long db = CreateDatabase(instance, "data/app.db", "");
if (db != 0)
{
int ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
CloseDatabase(instance, db);
}python
from ctypes import CDLL, c_int, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
db = ola.CreateDatabase(instance, b"data/app.db", b"")
if db:
ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)")
ola.CloseDatabase(instance, db)返回值
数据库对象指针。若创建失败,返回 0。
